package org.jackysoft.data;

import java.io.File;
import java.io.Serializable;
import java.util.Collection;

import org.jackysoft.entity.Identifiable;
import org.jackysoft.google.collection.ZTreeNode;
import org.jackysoft.query.Query;
import org.jackysoft.util.FileInfo;
import org.jackysoft.util.Page;
import org.springframework.dao.DataAccessException;

import com.mongodb.DBObject;

public interface CRUDDataProvider<ID extends Serializable,T extends Identifiable> {
	/**
	 * @param id mongo 数据对象对象 sid 
	 * */
	T get(ID id) throws DataAccessException;
	
	T get(DBObject query) throws DataAccessException;

	Collection<T> gets(int start, int size) throws DataAccessException;
	
	Collection<T> gets(int start, int size,DBObject sort) throws DataAccessException;
	
	Collection<T> query(int start, int size,DBObject query) throws DataAccessException;
	
	Collection<T> query(int start, int size,DBObject query,DBObject sort) throws DataAccessException;
	
	/**
	 * 返回该节点下的所有业务子节点
	 * @param bean 父节点，必须要有@ID标识的属性
	 * @return 子节点
	 * */
	Collection<ZTreeNode> ztree(T bean)  throws DataAccessException;

	/**
	 * 
	 * @param page
	 *            页码
	 * @param rows
	 *            每页条数
	 * @return 包含了数据的页对象
	 * @see Page
	 * 
	 * */
	Page getsPage(Integer start, Integer rows) throws DataAccessException;

	Collection<T> gets() throws DataAccessException;

	Page query(Query qc, Integer start, Integer rows)
			throws DataAccessException;

	Page  details(Query qc, Integer pindex, Integer rows)throws DataAccessException;
	
	Collection<T> gets(DBObject query)throws DataAccessException;
	
	Collection<T> getsAndSort(DBObject query,DBObject sort)throws DataAccessException;
	
	void create(T b) throws DataAccessException;

	void create(File[] files, String[] names) throws Exception;

	void create(File file, String name) throws Exception;
	
	void create(File file, String name,T bean) throws Exception;

	void create(Collection<T> bs) throws DataAccessException;

	FileInfo download(String id) throws Exception;
	
	void remove(T t) throws DataAccessException;
	
	void remove(String  id) throws DataAccessException;

	void remove(Collection<T> bs) throws DataAccessException;

	void removeAll() throws DataAccessException;
	
	void update(T b) throws DataAccessException;
	
	
	void update(Collection<T> bs) throws DataAccessException;

	void saveOrUpdate(T b) throws DataAccessException;

	int count() throws DataAccessException;

	int count(DBObject query);
	
	int count(Query qc) throws DataAccessException;
	
	/**
	 * 对指定集合进行排序,内存临时排序
	 * */
	public void sorts(Collection<T> beans) ;	
	
	/**
	 * 保存排序结果
	 * 持久化到数据库
	 * */
	void sorted(Collection<T> beans) throws Exception;

}
